$.namespace('square');

square = function() {

	return {
		init : function() {
			EasyUIInit.initControls([this.config.grid,this.config.dialog]); 
		},
		showForm : function() {
			alert('aaa');
			$('#fmDlg').show().dialog('open');
			$('#fm').form('clear');
		},
		showEditForm : function() {
			var row = $('#grid').datagrid('getSelected');
			if (!row) {
				$.messager.alert('提示', '请选择要修改的数据.', 'info');
				return;
			}
			$('#fmDlg').show().dialog('open');
			$('#fm').form('load', row);
			/*
			var fm = $('#fm');
			//if (fm.form('validate')) 
			{
				//url = ctxRest + '/pms/org/create';
				var obj= $.serializeObject(fm);
				
				console.log(obj);
			}
			*/
		}		
	}
}();


square.config = {
	grid : {
		id : "grid",
		type : "easyui-datagrid",
		option : {
			title : '广场列表',
			url : ctx + '/rest/gcb/square/findList',
			contentType : 'application/json;charset=utf-8',
			idField : 'id',
			fitColumns : true,
			toolbar:"#toolbar",
			columns : [ [ {
				title : 'ID',
				field : 'id',
				width : 30
			}, {
				title : 'code',
				field : 'code',
				width : 50
			}, {
				title : 'name',
				field : 'name',
				width : 80
			}, {
				title : 'function',
				field : 'function',
				width : 80
			}, {
				title : 'region',
				field : 'region',
				width : 80
			}, {
				title : 'bgColor',
				field : 'bgColor',
				width : 20
			}, {
				title : 'lineColor',
				field : 'lineColor',
				width : 20
			}, {
				title : 'lineWidth',
				field : 'lineWidth',
				width : 30
			}, {
				title : 'center',
				field : 'center',
				width : 30
			}, {
				title : 'textCenterssss',
				field : 'textCenter',
				width : 30
			}, {
				title : 'status',
				field : 'status',
				width : 20
			} ] ],
			
			toolbar: [{
				text:'增加',
				iconCls: 'icon-add',
				handler: square.showForm,
			},'-',{
				text:'修改',
				iconCls: 'icon-edit',
				handler: square.showEditForm,
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){alert('帮助按钮')}
			}],
			
			onDblClickRow : square.showEditForm
		}

	},
	dialog : {
		id : 'fmDlg',
		type : 'easyui-dialog',
		style : 'padding:5px;',
		option : {
			title : '广场信息',
			width : 600,
			height : 280 ,
			closed : true,
			buttons:[{
				text:'保存',
				handler:function(){;}
			},{
				text:'关闭',
				handler:function(){;}
			}]
		},
		controls:[{
		  		id : 'fm',
				type : 'form',
				isExternal:true,
				style : 'padding:5px;',   
				layout : {
					captionWidth : 80,
					fieldWidth : 200,
					fieldHeight : 28,
					rowHeight : 30,
					columns : 2,
					controls : [{id:'code',caption:'广场编号',type:'easyui-textbox',option:{required:true,validType:['length[0,20]'],invalidMessage:'最大长度为20！'}},
					            {id:'name',caption:'广场名称',type:'easyui-textbox',option:{required:true,validType:['length[0,50]'],invalidMessage:'最大长度为20！'}},
					            {id:'function',caption:'广场功能',type:'easyui-textbox',option:{required:true,validType:['length[0,100]'],invalidMessage:'最大长度为21！'}},
					            {id:'region',caption:'区域',type:'easyui-textbox',option:{required:true}},
					            {id:'bgColor',caption:'背景色',type:'input',isExternal:true,option:{required:true}},
					            {id:'lineColor',caption:'线条颜色',type:'input',isExternal:true,option:{required:true}},
					            {id:'lineWidth',caption:'线条宽度',type:'easyui-numberspinner'},
					            {id:'center',caption:'广场中心',type:'easyui-textbox'},
					            {id:'textCenter',caption:'文字中心',type:'easyui-textbox'},
					            {id:'status',caption:'状态',type:'easyui-textbox'},
					            ]
				}
		}]
	} 
};

$(function() {
	square.init();
})